package org.SoccerTournament.model;

import java.util.Collection;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.PrimaryKeyJoinColumn;
import javax.persistence.Table;

@Entity
@Table(name = "Teams")
public class Team {
	
	@Id
	@GeneratedValue
	@Column(name="teamId")
	private Long teamId;
	
	private Zone zone;
	
	private String name;
    
	
	@OneToMany(cascade = CascadeType.ALL)
	@JoinColumn(name="teamId")
	private Set<Player> players = new HashSet<Player>();
	
	
	@ManyToMany(cascade = CascadeType.ALL,fetch = FetchType.LAZY)
	@JoinTable(
			name = "team_stadium",
			joinColumns = { @JoinColumn(name="teamId")},
			inverseJoinColumns = {@JoinColumn(name="stadiumId")} 
	)
    private Set<Stadium> stadiums = new HashSet<Stadium>();
	
	
	@OneToOne (cascade = CascadeType.ALL,fetch = FetchType.LAZY,targetEntity = Zone.class)
	@PrimaryKeyJoinColumn
	public Zone getZone() {
		return zone;
	}
	
	public Set<Stadium> getStadiums() {
    	return stadiums;
    }
    
	
	public void addPlayer(Player player){
		this.getPlayers().add(player);
	}
	
	
	public void addStadium(Stadium stadium){
		this.getStadiums().add(stadium);
	}
	
	
	public Long getTeamId() {
		return teamId;
	}
	
	public Collection<Player> getPlayers() {
		return players;
	}

	@Column(name = "name")
	public String getName() {
		return name;
	}
	
	
	public void setName(String name) {
		this.name = name;
	}

	
	public void setZone(Zone zone) {
		this.zone = zone;
	}
	
	
	public void setPlayers(Set<Player> players) {
		this.players = players;
	}
	
	
	public void setStadiums(Set<Stadium> stadiums) {
		this.stadiums = stadiums;
	}
	
	
	public void setTeamId(Long teamId) {
		this.teamId = teamId;
	}
}
